import React from 'react'
import '../../assets/css/cart/succeed.less'
import {withRouter} from 'react-router-dom'
class SucceedComponents extends React.Component{
    constructor(){
        super()
        this.state={
            code:0
        }
    }
    getCode(){
        fetch(
            'http://vueshop.glbuys.com/api/order/lastordernum?uid='+localStorage['uid']+'&token=1ec949a15fb709370f',
            {
                method: 'get'
            }
        )
            .then((res) => res.json())
            .then((res) => {
                console.log(res)
                if (res.code === 200) {
                    this.setState({
                        code:res.data.ordernum
                    })
                }
            })
    }
    componentWillMount() {
        this.getCode()
    }
    goInfo(path,code){
        this.props.history.push({
            pathname:path,
            query:{
                id:code
            }
        })
    }
    goBack(){
        console.log(this.props.history);
        this.props.history.goBack()
    }
    render() {
        return(
            <div id='succeed'>
                <div className='header'>
                    <div onClick={this.goBack.bind(this)}>
                        <img src="/images/user/my/返回.png" alt=""/>
                    </div>
                    <div>下单成功</div>
                    <div></div>
                </div>
                <div className='txt'>
                    <div>下单成功!</div>
                    <div>订单编号:{this.state.code}</div>
                    <div onClick={this.goInfo.bind(this,'/profile/allorder','all')}>查看订单</div>
                    <div  onClick={this.goInfo.bind(this,'/profile/allorder','0')}>去付款</div>
                </div>

            </div>
        )
    }
}
export default withRouter(SucceedComponents)
